package com.suntront.module_datasynch.adapter;

import android.content.Context;
import android.graphics.Color;
import android.widget.CheckBox;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.mtjsoft.www.kotlinmvputils.imp.AdapterItemClickListener;
import com.suntront.module_datasynch.R;
import com.suntront.module_datasynch.model.TaskDownModel;

import java.util.List;

/**
 * @author mtj
 * @Package com.suntront.module_datasynch.adapter
 * @date 2020-05-26 10:28:33
 */

public class TaskDownAdapter extends BaseQuickAdapter<TaskDownModel, BaseViewHolder> {

    private Context context;
    private AdapterItemClickListener adapterItemClickListener;

    public TaskDownAdapter(Context context, List<TaskDownModel> list, AdapterItemClickListener adapterItemClickListener) {
        super(R.layout.item_taskdown, list);
        this.context = context;
        this.adapterItemClickListener = adapterItemClickListener;
    }

    @Override
    protected void convert(BaseViewHolder holder, TaskDownModel model) {
        int position = holder.getLayoutPosition();
        holder.setText(R.id.meter_name, model.getRosterName());
        CheckBox checkBox = holder.getView(R.id.meter_choose);
        checkBox.setChecked(model.isChoose() && !model.isLoad());
        holder.setText(R.id.meter_load_state, model.isLoad() ? "已下载" : "未下载");
        holder.setTextColor(R.id.meter_load_state, model.isLoad() ? Color.GREEN : Color.RED);
        checkBox.setEnabled(!model.isLoad());
        checkBox.setOnCheckedChangeListener((buttonView, isChecked) ->
                model.setChoose(isChecked)
        );
    }
}